(in-package :skymech)

(defun main ()
    (iup:with-iup ()
        (let* ((space-field  (iup:multi-line  :expand "YES"
                                              :size "200x200"))
               (del          (iup:text :spin "YES" :spinmin 0))
               (path         (iup:text))
               (load-button  (iup:button
                              :title  "Загрузить"
                              :expand "NO"
                              :action (lambda (handle)
                                          (setf (iup:attribute space-field :value)
                                                (alexandria:read-file-into-string
                                                 (iup:attribute path :value))))))
               (start-button (iup:button
                              :title  "Старт"
                              :expand "NO"
                              :action (lambda (handle)
                                          (simulation (parse-space-from-string
                                                       (iup:attribute space-field :value))))))
               (control     (iup:vbox (list space-field
                                            del
                                            path
                                            (iup:hbox (list load-button
                                                            start-button)))))
               (dialog      (iup:dialog control :title "Небесная механника")))
            (iup:show dialog)
            (iup:main-loop))))

(defun interface ()
    (sb-int:with-float-traps-masked
        (:divide-by-zero :invalid)
        (main)))
